<script lang="ts" setup>
import { ref, onMounted, onActivated } from "vue";
import router from "@/router";
import applyForm from "./components/applyForm.vue";
import PageWrapper from "@/components/Wrapper";
import detailTable from "./components/detailTable.vue";
import operation from "./components/operation.vue";
import { setStocktakingOrderDetail } from "@/api/stocktakingOrder";

defineOptions({
  name: "inventoryCountPage"
});
const tableData = ref([]);

const tableHeight = ref(0);
const pageWrapperRef = ref();
const applyFormRef = ref(null);

onActivated(() => {
  const { id } = router.currentRoute.value.query;
  initData(id);
  pageWrapperRef.value.initData();
});

// 获取数据
const initData = (id: any) => {
  setStocktakingOrderDetail({ id: Number(id) }).then(rsp => {
    applyFormRef.value.setForm(rsp.data);
    tableData.value = rsp.data.itemList;
  });
};
</script>
<template>
  <div class="main_box">
    <PageWrapper
      ref="pageWrapperRef"
      v-model:height="tableHeight"
      :isShowLine="false"
    >
      <template #header>
        <applyForm ref="applyFormRef" />
      </template>
      <template #content>
        <div class="table_box">
          <operation />
          <detailTable :list="tableData" :tableHeight="tableHeight" />
        </div>
      </template>
    </PageWrapper>
  </div>
</template>
<style lang="scss" scoped></style>
